package com.hy.wsroom.handler.impl;

import com.hy.wsroom.entity.Message;
import com.hy.wsroom.enums.MessageTypeEnum;
import com.hy.wsroom.handler.MessageHandler;
import com.hy.wsroom.service.WebSocketClient;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UnsupportedMessageTypeHandler implements MessageHandler {
    private final WebSocketClient webSocketClient;
    @Override
    public MessageTypeEnum getType() {
        return MessageTypeEnum.UNSUPPORTED;
    }

    @Override
    public void handle(Message message) throws Exception {
        String from = message.getFrom();
        // 发送错误消息
        message.setType(MessageTypeEnum.UNSUPPORTED.getType());
        message.setContent("不支持的消息类型");
        message.setTo(from);
        message.setBroadcast(false);
        webSocketClient.sendTextMessage(message);
    }
}
